// pages/user/components/home/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    coupons:{
      type:Array,
      value:[]
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    paramsState:{
      typeId:'推荐'
    },
    flag:false,
    menu:[
      {
        text:'推荐',
      },
      {
        text:'休闲娱乐',
      },
      {
        text:'旅游酒店',
      },
      {
        text:'美容美发',
      },
      {
        text:'美食',
      }
    ],
    banner:[
      {
        text:'推荐'
      },
      {
        text:'推荐'
      },
      {
        text:'推荐'
      }
      
    ],
    
  },

  /**
   * 组件的方法列表
   */
  methods: {
    changeMain(event){
      let that = this;
      let typeId = event.currentTarget.dataset.typeId;
      if(typeId === that.data.paramsState.typeId)return;
      // 更新菜单项
      that.setData({
        paramsState:{
          typeId:typeId
        }
      })
      // 重新发出请求
      that.getInfo(typeId)
      // console.log(that)
    },
    getInfo(typeId){
      let that = this;
      that.setData({
        flag:true
      })
      setTimeout(()=>{
        that.setData({
          ['banner']:that.createNewBanner(typeId),
          ['coupons']:that.createNewCus(typeId),
          flag:false
        },function(){
          
          console.log('更新完成，关闭flag')
        })
      },500)
    },
    createNewCus(typeId){
      return[
        {text:typeId},
        {text:typeId},
        {text:typeId},
        {text:typeId},
        {text:typeId},
        {text:typeId}
      ]
    },
    createNewBanner(typeId){
      return [
        {text:typeId},
        {text:typeId},
        {text:typeId}
      ]
    }
  },
})
